package test.data_structure.queue;

import test.data_structure.array.DynamicArray;
import test.data_structure.array.MyArray;

public class MyArrayQueue<T> implements Queue<T> {

    private DynamicArray<T> data;

    public MyArrayQueue(int capacity) {
        data = new DynamicArray<>(capacity);
    }

    public MyArrayQueue() {
        data = new DynamicArray<>();
    }

    @Override
    public boolean isEmpty() {
        return data.isEmpty();
    }

    @Override
    public int getSize() {
        return data.getSize();
    }

    public int getCapacity() {
        return data.getCapacity();
    }

    @Override
    public void enqueue(T data) {
        this.data.addLast(data);
    }

    @Override
    public T dequeue() {
        return this.data.removeFirst();
    }

    @Override
    public T getFront() {
        return this.data.get(0);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Queue:");
        sb.append("front [");
        for (int i = 0 ; i < this.data.getSize() ; i ++) {
            sb.append(this.data.get(i));
            if (i != this.getSize() - 1) {
                sb.append(",");
            }
        }
        sb.append("] tail");
        return sb.toString();
    }

    public static void main(String[] args) {
        MyArrayQueue<Integer> queue = new MyArrayQueue<>();
        for (int i = 0 ; i < 10 ; i ++) {
            queue.enqueue(i);
            System.out.println(queue);
            if (i % 3 == 2) {
                queue.dequeue();
                System.out.println(queue);
            }
        }
    }
}
